"""
Copyright 2012 Wieser Dietmar, Margit Mutschlechner.

This file is part of Multimedia Social Networking Platform.

Multimedia Social Networking Platform is free software: 
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Multimedia Social Networking Platform is distributed
in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Multimedia Social Networking Platform.  
If not, see <http://www.gnu.org/licenses/>.

"""

import threading
from msnp.logger import Logger

"""This module contains all ten locks needed.

It contains acquire and release functions for each Lock instance.
"""

__joinLock = threading.Lock()
__fingerLock = threading.Lock()
__keepAliveLock = threading.Lock()
__backupLock = threading.Lock()
__crashTimerLock = threading.Lock()
__rtLock = threading.Lock()
__sendBackupLock = threading.Lock()
__crashFinishLock = threading.Lock()
__mediaLock = threading.Lock()
__sendMediaLock = threading.Lock()

def acquireJoinLock():
    global __joinLock
    Logger.info("acquire joinlock")
    __joinLock.acquire()
    Logger.info(" joinlock acquired")
    
def releaseJoinLock():
    global __joinLock
    Logger.info("release joinlock")
    __joinLock.release()
    Logger.info(" joinlock released")
    
def acquireFingerLock():
    global __fingerLock
    Logger.info("acquire fingerlock")
    __fingerLock.acquire()
    Logger.info(" fingerlock acquired")
    
def releaseFingerLock():
    global __fingerLock
    Logger.info("release fingerlock")
    __fingerLock.release()
    Logger.info(" fingerlock released")
    
def acquireKeepAliveLock():
    global __keepAliveLock
    __keepAliveLock.acquire()
    
def releaseKeepAliveLock():
    global __keepAliveLock
    __keepAliveLock.release()
    
def acquireBackupLock():
    global __backupLock
    Logger.info("acquire backuplock")
    __backupLock.acquire()
    Logger.info(" backuplock acquired")
    
def releaseBackupLock():
    global __backupLock
    Logger.info("release backuplock")
    __backupLock.release()
    Logger.info(" backuplock released")
    
def acquireCrashTimerLock():
    Logger.info("acquire crashtimerlock")
    global __crashTimerLock
    __crashTimerLock.acquire()
    Logger.info(" crashtimerlock acquired")
    
def releaseCrashTimerLock():
    global __crashTimerLock
    Logger.info("release crashtimerlock")
    __crashTimerLock.release()
    Logger.info("  crashtimerlock released")
    
def acquireRTLock():
    Logger.info("acquire __rtLock")
    global __rtLock
    __rtLock.acquire()
    Logger.info(" __rtLock acquired")
    
def releaseRTLock():
    global __rtLock
    Logger.info("release __rtLock")
    __rtLock.release()
    Logger.info(" __rtLock released")
    
def acquireSendBackupLock():
    global __sendBackupLock
    __sendBackupLock.acquire()
    
def releaseSendBackupLock():
    global __sendBackupLock
    __sendBackupLock.release()
    
def acquireCrashFinishLock():
    global __crashFinishLock
    Logger.info("acquire __crashFinishLock")
    __crashFinishLock.acquire()
    Logger.info(" __crashFinishLock acquired")
    
def releaseCrashFinishLock():
    global __crashFinishLock
    Logger.info("release __crashFinishLock")
    __crashFinishLock.release()
    Logger.info(" __crashFinishLock released")
    
def acquireMediaLock():
    global __mediaLock
    Logger.info("acquire __mediaLock")
    __mediaLock.acquire()
    Logger.info(" __mediaLock acquired")
    
def releaseMediaLock():
    global __mediaLock
    Logger.info("release __mediaLock")
    __mediaLock.release()
    Logger.info(" __mediaLock released")
        
def acquireSendMediaLock():
    global __sendMediaLock
    Logger.info("acquire __sendMediaLock")
    __sendMediaLock.acquire()
    Logger.info(" __sendMediaLock acquired")
    
def releaseSendMediaLock():
    global __sendMediaLock
    Logger.info("release __sendMediaLock")
    __sendMediaLock.release()
    Logger.info(" __sendMediaLock released")

